package adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;

import java.util.List;
import java.util.Map;

import application.App;
import student.andlei.com.student.R;
import utils.GlideUtils;
import utils.StringUtils;

public class IMMessageAdapter extends BaseQuickAdapter<ChatRoomMessage,BaseViewHolder>{
    public IMMessageAdapter(int layoutResId, @Nullable List<ChatRoomMessage> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ChatRoomMessage item) {
        Map<String,Object> map =  item.getRemoteExtension();
        if(map ==null ){return;}
        if(map.get("avatar")!=null){
            GlideUtils.loadImageViewHeadphotoLoding(App.getInstance(),map.get("avatar")+"", (ImageView) helper.getView(R.id.cimg_headimg));
        }
        if(map.get("name")!=null){
            helper.setText(R.id.tv_user_name,map.get("name")+"");
        }
        if(!StringUtils.isNull(item.getContent())){
            helper.setText(R.id.tv_user_message,item.getContent());
        }

    }
}
